package com.yunkeji.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunkeji.common.core.domain.PageQuery;
import com.yunkeji.common.core.page.TableDataInfo;
import com.yunkeji.dao.domain.PhoneLog;
import com.yunkeji.dao.mapper.PhoneLogMapper;
import com.yunkeji.dao.vo.PhoneLogVo;
import com.yunkeji.system.service.IPhoneLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 手机号码修改记录业务层处理
 *
 * @author 雷擎宇
 * @date 2024-11-14
 */
@RequiredArgsConstructor
@Service
public class PhoneLogServiceImpl implements IPhoneLogService {

    private final PhoneLogMapper baseMapper;

    @Override
    public TableDataInfo<PhoneLogVo> queryPageList(PhoneLog bo, PageQuery pageQuery) {
        LambdaQueryWrapper<PhoneLog> lqw = buildQueryWrapper(bo);
        Page<PhoneLogVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    private LambdaQueryWrapper<PhoneLog> buildQueryWrapper(PhoneLog log) {
        LambdaQueryWrapper<PhoneLog> lqw = Wrappers.lambdaQuery();
        lqw.eq(log.getPlatformId() != null, PhoneLog::getPlatformId, log.getPlatformId());
        lqw.orderByDesc(PhoneLog::getCreateTime);
        return lqw;
    }

    @Override
    public Boolean insert(PhoneLog log) {
        baseMapper.insert(log);
        return true;
    }

}
